package main

import (
	"github.com/gin-gonic/gin"
	"go-project/common"
	"go-project/common/casbininit"
	"go-project/routes"
	"log"
)

//init
func init() {
	//setting
	err := common.SetupSetting()
	if err != nil {
		log.Fatalf("init.setupSetting err: %v", err)
	}

	////logger
	//err = global.SetupLogger()
	//if err != nil {
	//	log.Fatalf("init.SetupLogger err: %v", err)
	//}

	// //access logger
	// err = global.SetupAccessLogger()
	// if err != nil {
	// 	log.Fatalf("init.SetupAccessLogger err: %v", err)
	// }
	//db
	err = common.SetupDbLink()
	if err != nil {
		log.Fatalf("init.SetupLogger err: %v", err)
	}
	//casbin
	err = casbininit.SetupCasbinEnforcer()
	if err != nil {
		log.Fatalf("init.SetupCasbinEnforcer err: %v", err)
		// global.Logger.Fatalf("init.SetupCasbinEnforcer err: %v", err)
	}
}

func main() {
	gin.SetMode(common.ServerSetting.RunMode)
	r := gin.Default()
	//初始化路由
	routes.InitRoute(r)
	// 初始化数据
	r.Run(":" + common.ServerSetting.HttpPort)
	defer common.DB.Close()
}
